#define demo1

#ifdef demo1
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[]) {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}
#endif

#ifdef demo2
#include <QCoreApplication>
#include <QTcpSocket>
#include <QDebug>

int main(int argc, char *argv[]) {
    QCoreApplication a(argc, argv);

    QTcpSocket socket;
    socket.connectToHost("baidu.com", 80);

    if(socket.waitForConnected(3000)) {
        qDebug() << "Connected!";
        socket.write("GET / HTTP/1.1\r\n\r\n");
        socket.waitForBytesWritten(1000);
        socket.waitForReadyRead(3000);
        qDebug() << "Response: " << socket.readAll();
    } else {
        qDebug() << "Not connected!";
    }

    return a.exec();
}
#endif


#ifdef demo3
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QDebug>

class Downloader : public QObject {
Q_OBJECT

public:
    Downloader(const QUrl &url, QObject *parent = nullptr) : QObject(parent) {
        connect(&manager, &QNetworkAccessManager::finished, this, &Downloader::onFinished);
        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::UserAgentHeader, "MyApp 1.0");
        manager.get(request);
    }

private slots:
    void onFinished(QNetworkReply *reply) {
        if (reply->error() == QNetworkReply::NoError) {
            QByteArray data = reply->readAll();
            qDebug() << "Data received:" << data;
        } else {
            qDebug() << "Error:" << reply->errorString();
        }
        reply->deleteLater();
        QCoreApplication::quit();
    }

private:
    QNetworkAccessManager manager;
};

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    QUrl url("http://jsonplaceholder.typicode.com/posts");
    Downloader downloader(url);

    return app.exec();
}

#include "main.moc"
#endif

